package com.chat.module.act;

import com.chat.comment.core.ResponseResult;
import com.chat.module.act.vo.ChatInfoActionVo;
import com.chat.module.message.domain.ChatInfoLog;
import com.chat.module.message.service.impl.ChatInfoLogServiceImpl;
import com.comment.util.JwtUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Set;

@RestController
@RequestMapping("/chatInfoAct")
public class ChatInfoAction {
    @Resource
    private ChatInfoLogServiceImpl chatInfoLogService;
    @ApiOperation("查看历史记录50条")
    @PostMapping("/viewHistory")
    public ResponseResult<ChatInfoLog> chat(
            @RequestHeader String token,
            @RequestBody ChatInfoActionVo.ViewHistory vo
    ) {
        Set<Long> userIds = vo.getUserIds();
        userIds.add(JwtUtils.getPlayerId(token));
        return ResponseResult.success(chatInfoLogService.obtainChatInfoBy(
                vo.getCode(), userIds , 50
        ));
    }
    @ApiOperation("查询会话")
    @PostMapping("/select")
    public ResponseResult<ChatInfoLog> select(
            @RequestHeader String token,
            @RequestBody ChatInfoActionVo.select vo
    ) {
        return ResponseResult.success(chatInfoLogService.selectBy(
                JwtUtils.getPlayerId(token),vo.getId()
        ));
    }
}
